home *** CD-ROM | disk | FTP | other *** search
/ IRIS Performer 2.2 Friends Demo / SGI IRIS Performer 2.2 Friends Demo.iso / friends / devices / BGSystems / bg / pack.c < prev    next >
C/C++ Source or Header  |  1997-10-31  |  1KB  |  62 lines

  1. /*
  2.  * Copyright 1992-4   BG Systems, Inc.
  3.  * pack.c
  4.  *
  5.  * Routine to pack data for outputs
  6.  *
  7.  * Author         Date       Comments
  8.  * John Green     21-Oct-94  Major revision for v 3.0 EPROM
  9.  * John Green     28-Jan-95  Change order for packing outputs
  10.  * John Green     01-Feb-95  Final touches for release
  11.  * John Green     15-Mar-95  Fix bug for dig outputs
  12.  */
  13.  
  14. static char SccsId[] = "@(#)pack.c    1.3 16 Mar 1995";
  15.  
  16. #include <stdio.h>
  17.  
  18. #include "lv3.h"
  19.  
  20. /*
  21.  *  This routine converts the compressed data string from
  22.  *  characters to 8 floats and a single 16 bit int for
  23.  *  the discretes
  24.  */
  25.  
  26. int pack_data(bglv *bgp, char * out_buf)
  27. {
  28.    int   i,k;
  29.    out_buf[0] = 'p';
  30.    i = 1;
  31.   
  32. /*
  33.  *  Load the 3 digital values into out_buf
  34.  */
  35.    for ( k = 2; k >= 0; k-- )
  36.    {
  37.       if ( bgp->dig_out >> k & 0x10 )
  38.       {
  39.          out_buf[i++] = ((bgp->dout[k]>>4) & 0xf ) + 0x21;
  40.          out_buf[i++] = (bgp->dout[k] & 0xf ) + 0x21;
  41.       }
  42.    }
  43. /*
  44.  *  Load the 3 analog values into out_buf
  45.  */
  46.    for (k = 0; k < 3; k++)
  47.    {
  48.       if ( ( bgp->analog_out >> k ) & 0x1 )
  49.       {
  50.          out_buf[i++] = (( bgp->aout[k] >> 6 ) & 0x3f) + 0x21;
  51.          out_buf[i++] = (bgp->aout[k] & 0x3f) + 0x21;
  52.       }
  53.    }
  54. /*
  55.  *  And terminate the string
  56.  */
  57.    out_buf[i++] = '\n';
  58.    out_buf[i++]   = '\0';
  59.  
  60.    return(0);
  61. }
  62.